package spindles.gwt.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.KeyboardListener;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class InfoDialog extends DialogBox {
	
	public static final String ABOUT_TITLE = "About the Spindles Application";

	public static final String ABOUT_BODY = "This application was developed for the Sleep Research Unit "
			+ "at Aiginiteio Hospital.</br>"
			+ "People involved are: Errikos M. Ventouras, Periklis Y. Ktonas, "
			+ "Hara Tsekou and Gjergji Strakosha.";

	public InfoDialog(String title, String body) {
		// Use this opportunity to set the dialog's caption.
		setText(title);

		// Create a VerticalPanel to contain the 'about' label and the 'OK' button.
		VerticalPanel outer = new VerticalPanel();

		// Create the 'about' text and set a style name so we can style it with CSS.

		HTML text = new HTML(body);
		text.setStyleName("spindles-AboutText");
		outer.add(text);

		// Create the 'OK' button, along with a listener that hides the dialog
		// when the button is clicked.
		outer.add(new Button("Close", new ClickListener() {
			public void onClick(Widget sender) {
				hide();
			}
		}));

		setWidget(outer);
	}
	
	public InfoDialog(String title, String header, String content){
		// Use this opportunity to set the dialog's caption.
		setText(title);

		// Create a VerticalPanel to contain the 'about' label and the 'OK' button.
		VerticalPanel outer = new VerticalPanel();

		// Create the 'about' text and set a style name so we can style it with CSS.

		DisclosurePanel mainPanel = new DisclosurePanel(header);
		
		TextArea contentArea = new TextArea();
		contentArea.setText(content);
		contentArea.setCharacterWidth(400);
		contentArea.setVisibleLines(7);
		
		mainPanel.setContent(contentArea);
		
		
		outer.add(mainPanel);

		// Create the 'OK' button, along with a listener that hides the dialog
		// when the button is clicked.
		outer.add(new Button("Close", new ClickListener() {
			public void onClick(Widget sender) {
				hide();
			}
		}));

		setWidget(outer);
	}	

	public boolean onKeyDownPreview(char key, int modifiers) {
		// Use the popup's key preview hooks to close the dialog when either
		// enter or escape is pressed.
		switch (key) {
		case KeyboardListener.KEY_ENTER:
		case KeyboardListener.KEY_ESCAPE:
			hide();
			break;
		}

		return true;
	}
}
